<template>
    <div>
        <h3>当前最新的count值为:{{$store.state.count}}</h3>
        <h4>{{$store.getters.showNum}}</h4>
        <button @click="toadd">+1</button>
        <button @click="toaddn">+{{n}}</button>
        <button @click="waitadd">+1 Async</button>
        <button @click="waitaddn">+n Async</button>
    </div>
</template>

<script>
export default {
    data() {
        return {
            n:0
        }
    },
    methods: {
        //触发store里面mutation的自增方法
        toadd(){
            //commit的作用就是调用mutation里面的某个方法
            this.$store.commit('add')
        },
        toaddn(){
            this.$store.commit('addN',this.n)
        },
        waitadd(){
            this.$store.dispatch('addasync')
        },
        waitaddn(){
            this.$store.dispatch('addasyncn',this.n)
        },
        refresh(){
            console.log('addtion里面的refresh')
        }

    },
    created() {
        this.n = 8
    },
    

}
</script>

<style>

</style>